package com.zxl.controller;

import com.zxl.feign.GoodsFeign;
import com.zxl.vo.GoodsType;
import com.zxl.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @packageName com.zxl.controller
 * @ClassName
 * @Author zxl
 * @Description //TODO
 * @date
 **/
@Controller
@RequestMapping("/goodstype")
public class GoodsTypeController {

    @Autowired
    private GoodsFeign goodsTypeFeign;

    @RequestMapping("/{page}.html")
    public String page(@PathVariable("page") String page,Integer id,Model model){
        model.addAttribute("id",id);
        return "/goods/"+page;
    }

    @RequestMapping("/list")
    public String list(Model model){
        List<GoodsType> list = goodsTypeFeign.list();
        model.addAttribute("goodsTypes",list);
        return "goods/goodsTypeList";
    }

    @RequestMapping("/tree")
    public String tree(){
        return "goods/goodstypeTree";
    }


    @RequestMapping("/getGoodsTypeTree")
    @ResponseBody
    public List<GoodsType> getGoodsTypeTree(){
        return goodsTypeFeign.list();
    }

    @PostMapping("/updateGoodsType")
    @ResponseBody
    public R updateGoodsType(GoodsType goodsType){
        return R.write(goodsTypeFeign.updateGoodsType(goodsType));
    }

    @RequestMapping("/deleteGoodsTypeById/{id}")
    @ResponseBody
    public R deleteGoodsTypeById(@PathVariable("id") Integer id){
        return R.write(goodsTypeFeign.deleteGoodsTypeById(id));
    }
    @PostMapping("/addGoodsType")
    @ResponseBody
    public R addGoodsType(GoodsType goodsType){
        return R.write(goodsTypeFeign.addGoodsType(goodsType));
    }

    @RequestMapping("/findByPid")
    @ResponseBody
    public List<GoodsType> findById(Integer pid){
        return goodsTypeFeign.findGoodsTypeById(pid);
    }
}
